package gx.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import gx.service.SaleItemService;

@Controller
@RequestMapping("/mng/scount")
public class ScountController {
	@Autowired
	private SaleItemService saleItemService;

	// 2017年商品销售统计图
	@RequestMapping("/list.jhtml")
	public ModelAndView sale() {
		ModelAndView mav = new ModelAndView("/mng/scount/list");
		int year = 2017;
		Map<String, Long> map = saleItemService.totaInventory(year);
		StringBuffer m = new StringBuffer();// 月份
		StringBuffer data = new StringBuffer();// 数量
		int i = 0;
		for (Map.Entry<String, Long> maps : map.entrySet()) {
			if (i++ > 0) {
				m.append(",");
				data.append(",");
			}
			m.append("'");
			m.append(maps.getKey());
			m.append("'");
			data.append(maps.getValue().longValue());
		}
		mav.addObject("year", year);
		mav.addObject("months", m.toString());
		mav.addObject("datas", data.toString());
		// 2017年商品分类出库比例图
		Map<String, Long> map_c = saleItemService.totaInventoryByCategory(year);
		StringBuffer datas2 = new StringBuffer();
		int j = 0;
		for (Map.Entry<String, Long> mentry : map_c.entrySet()) {
			if (j++ > 0) {
				datas2.append(",");
			}
			datas2.append("['" + mentry.getKey() + "'," + mentry.getValue() + "]");
		}
		
		System.out.println(data.toString());
		System.out.println(m.toString());

		System.out.println(datas2.toString());
		mav.addObject("datas2", datas2);
		return mav;//ctrl+shift+F
	}

}
